<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>
    <ul class="clearfix back_bgf border_3 border_c pr30 pl20 pt20 pb20 height32 fontc_666">
        <form action="<?php echo $this->createUrl('/problem/rules/index')?>" method="get" name="search">
            <li class="fl pt10 pr20 pb10 pl8">
                <span class="fl pr3">规则代码：</span>
                <input type="text" value="<?php echo $search['code']; ?>" name="code" class="fl pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
            </li>
            <li class="fl pt10 pr30 pb10 pl3">
                <span class="fl pr3">规则名称：</span>
                <input type="text" value="<?php echo $search['name']; ?>" name="name" class="fl pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
            </li>         
            <li class="fr pt10 pb10">
                <input type="submit" value="查询" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            </li>
        </form>
    </ul>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
            <input type="button" value="新增" onclick="addrules()" style="margin-right:30px;" class="fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 mr10 cursor" />
            <input type="button" value="删除" onclick="delete_all()" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
        </div>
        <table class="height40">
            <thead class="back_bgf5 fontc_666">
                <tr>
                    <th width="50" align="center" class="m_hr_t m_hr_b pl10"><input type="checkbox" class="checkboxs"></th>
                    <th width="75" align="center" class="m_hr_t m_hr_b">代码</th>
                    <th width="85" align="center" class="m_hr_t m_hr_b">规则名称</th>
                    <th width="160" align="center" class="m_hr_t m_hr_b">对应数据表</th>
                    <th width="130" align="center" class="m_hr_t m_hr_b">包含考试号为空的数据</th>
                    <th width="62" align="center" class="m_hr_t m_hr_b">是否生效</th>
                    <th width="105" align="center" class="m_hr_t m_hr_b">备注</th>
                    <th width="115" align="center" class="m_hr_t m_hr_b pr5">操作</th>
                </tr>
            </thead>
            <tbody class="fontc_444">
                <?php if (!empty($rules)): ?>
                    <?php
                    $tableinfo = ZTask::_gettable();
                    foreach ($rules as $one):
                        ?>
                        <tr>
                            <td align="center" class="m_hr_b pl10"><input type="checkbox" name="deleteAll[]" value="<?php echo $one['id'];?>" class="checkbox"></td>
                            <td align="center" class="m_hr_b"><?php echo $one['code']; ?></td>
                            <td align="center" class="m_hr_b height20 pt5 pb5"><?php echo $one['name']; ?></td>
                            <td align="center" class="m_hr_b height20 pt5 pb5"><?php echo $tableinfo[$one['sqlname']]; ?></td>
                            <td align="center" class="m_hr_b"><input type="checkbox" <?php if ($one['is_exam'] == 1): ?>checked<?php endif; ?> disabled ></td>
                            <td align="center" class="m_hr_b"><input type="checkbox" <?php if ($one['is_show'] == 1): ?>checked<?php endif; ?> disabled ></td>
                            <td align="center" class="m_hr_b height20 pt5 pb5"><font title="<?php echo $one['remark'];?>"><?php echo Func::get_word($one['remark'], 12);?></font></td>
                            <td align="center" class="m_hr_b pr5">
                                <a onclick="javascript:window.location.href = '<?php echo $this->createUrl('/problem/rules/problemruledetail', array('problemrule_id' => $one['id'])); ?>'" class="mr10 cursor" title="字段设置"><img src="/themes/default/images/Sipei/plus.png"/></a>
                                <a href="javascript:;" onclick="editrules(<?php echo $one['id']; ?>)" title="编辑" class="mr10">
                                    <img src="/themes/default/images/Sipei/edit.png" class="cursor" />
                                </a>
                                <a href="javascript:;" onclick="deleterule(<?php echo $one['id']; ?>, $(this),<?php echo $one['is_show'];?>)" class="cursor" title="删除"><img src="/themes/default/images/Sipei/delate.png" /></a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr><td colspan="8" align="center" class="m_hr_b">暂时没有用户数据</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "url" => $pageUrl)); ?>
    </div>
</div>
<script>
                function editrules(id) {

                    api = $.dialog({
                        id: 'testID2',
                        lock: true,
                        fixed: true,
                        title: "编辑",
                        width: 580,
                        height: 500,
                        max: false,
                        min: false
                    });
                    $.get('/problem/rules/addrules', {id: id}, function(html) {
                        api.content(html);
                    });

                }

                function deleterule(id, $this,is_del) {
             
                    $.dialog.confirm('确定删除吗', function() {
                   /*       $.get('/problem/rules/deleterules', {id: id}, function(data) {
                            if (data == 1) {
                                $this.parents("tr").remove();
                            } else {
                                alert("删除失败");
                            }
                        });*/
                    	$.get('/problem/rules/delete_all', {id: id}, function(data) {
                			if(data == 1){
              			       	 location.reload();
              			     }else if(data == 3){
              					 $.dialog.alert("请清空字段设置数据后再进行删除操作");
              					 return false;
              				 }else{
              					 $.dialog.alert("删除失败");
              					 return false;
              				}          
            			});
                    });

                }
                
                function delete_all(){
                	var aa='';
                		$("input[name='deleteAll[]']:checkbox:checked").each(function(){
							aa+=$(this).val()+',';
						});
					if(aa == ''){
						$.dialog.alert("请选择要删除条目");
						return false;
					}
					$.dialog.confirm('确定删除所选数据吗', function() {
                		aa+=0;
                		$.get('/problem/rules/delete_all', {id: aa}, function(data) {
	                			if(data == 1){
	              			       	 location.reload();
	              			     }else if(data == 3){
	              					 $.dialog.alert("请清空字段设置数据后再进行删除操作");
	              					 return false;
	              				 }else{
	              					 $.dialog.alert("删除失败");
	              					 return false;
	              				}          
                		});
                	});
                }
                
                function addrules() {

                    api = $.dialog({
                        id: 'testID2',
                        lock: true,
                        fixed: true,
                        title: "新增",
                        width: 580,
                        height: 500,
                        max: false,
                        min: false
                    });
                    $.get('/problem/rules/addrules', {}, function(html) {
                        api.content(html);
                    });

                }
					$(function() {
                    $(".checkboxs").click(function() {
                        var checkedS = $(this).attr("checked");
                        if (checkedS) {
                            $(".checkbox").attr("checked", true)
                        } else {
                            $(".checkbox").removeAttr("checked")
                        }
                    })

                })
</script>